package System_code;

import java.util.concurrent.locks.ReentrantLock;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ling
 * Date: 2022-08-09
 * Time: 15:29
 */
public class Demo25 {
    public static void main(String[] args) {
        ReentrantLock locker=new ReentrantLock(true);//传入true 开启公平锁模式
        try {
            //加锁
            //locker.lock();
            locker.tryLock();

            // 代码逻辑.... 如果中间抛出异常了, 就可能执行不到 unlock，使用放在finally中
        }finally {
            locker.unlock();
        }
    }
}
